Skip to content

104. Maximum Depth of Binary Tree#21

Open
TakayaShirai wants to merge 1 commit intomainfrom
104_maximum_depth_of_binary_tree
Open

104. Maximum Depth of Binary Tree#21
TakayaShirai wants to merge 1 commit intomainfrom
104_maximum_depth_of_binary_tree

Conversation

@TakayaShirai
Copy link
Copy Markdown
Owner

@TakayaShirai TakayaShirai self-assigned this Feb 11, 2026
final leftTreeDepth = maxDepth(root.left);
final rightTreeDepth = maxDepth(root.right);

return 1 + max(leftTreeDepth, rightTreeDepth);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

個人的には

return max(leftTreeDepth, rightTreeDepth) + 1;

と、複雑なものを先、簡単なものを後に置くのですが、趣味の範囲だと思います。


class Solution {
int maxDepth(TreeNode? root) {
int maxDepthHelper(TreeNode? node, int previousDepth) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

些末ですが、ここで定義されている時点で、スコープ的に maxDepth のヘルパーであることはほぼ自明なので、関数名から取り除いても構わないと思いました。

Suggested change
int maxDepthHelper(TreeNode? node, int previousDepth) {
int helper(TreeNode? node, int previousDepth) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants